package com.anyou.mall.pla.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.pla.domain.PosterInfo;
import com.anyou.mall.pla.service.IPosterInfoService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 广告弹窗管理Controller
 *
 * @author gaochaohao
 * @date 2022-03-18
 */
@Api(tags = "广告弹窗管理")
@RestController
@RequestMapping("/pla/posterInfo")
public class PosterInfoController extends BaseController
{
    @Autowired
    private IPosterInfoService posterInfoService;

    /**
     * 查询广告弹窗管理列表
     */
    @ApiOperation("查询广告弹窗管理列表")
    @PreAuthorize("@ss.hasPermi('pla:posterInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<List<PosterInfo>> list(PosterInfo posterInfo)
    {
        startPage();
        List<PosterInfo> list = posterInfoService.selectPosterInfoList(posterInfo);
        return getDataTable(list);
    }

    /**
     * 导出广告弹窗管理列表
     */
    @ApiOperation("导出广告弹窗管理列表")
    @PreAuthorize("@ss.hasPermi('pla:posterInfo:export')")
    @Log(title = "广告弹窗管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PosterInfo posterInfo)
    {
        List<PosterInfo> list = posterInfoService.selectPosterInfoList(posterInfo);
        ExcelUtil<PosterInfo> util = new ExcelUtil<PosterInfo>(PosterInfo.class);
        util.exportExcel(response, list, "广告弹窗管理数据");
    }

    /**
     * 获取广告弹窗管理详细信息
     */
    @ApiOperation("获取广告弹窗管理详细信息")
    @PreAuthorize("@ss.hasPermi('pla:posterInfo:query')")
    @GetMapping(value = "/{posterId}")
    public ApiResult<PosterInfo> getInfo(@PathVariable("posterId") Long posterId)
    {
        return ApiResult.success(posterInfoService.selectPosterInfoByPosterId(posterId));
    }

    /**
     * 新增广告弹窗管理
     */
    @ApiOperation("新增广告弹窗管理")
    @PreAuthorize("@ss.hasPermi('pla:posterInfo:add')")
    @Log(title = "广告弹窗管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody PosterInfo posterInfo)
    {
        return ApiResult.success(posterInfoService.insertPosterInfo(posterInfo));
    }

    /**
     * 修改广告弹窗管理
     */
    @ApiOperation("修改广告弹窗管理")
    @PreAuthorize("@ss.hasPermi('pla:posterInfo:edit')")
    @Log(title = "广告弹窗管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody PosterInfo posterInfo)
    {
        return ApiResult.success(posterInfoService.updatePosterInfo(posterInfo));
    }

    /**
     * 删除广告弹窗管理
     */
    @ApiOperation("删除广告弹窗管理")
    @PreAuthorize("@ss.hasPermi('pla:posterInfo:remove')")
    @Log(title = "广告弹窗管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{posterIds}")
    public ApiResult remove(@PathVariable Long[] posterIds)
    {
        return ApiResult.success(posterInfoService.deletePosterInfoByPosterIds(posterIds));
    }

    /**
     * 修改广告弹窗状态
     */
    @ApiOperation("修改广告弹窗状态")
    @PreAuthorize("@ss.hasPermi('pla:posterInfo:disable')")
    @Log(title = "广告弹窗管理", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/{posterId}")
    public ApiResult updatePosterStatus(@PathVariable("posterId") Long posterId) {
        return posterInfoService.updatePosterStatus(posterId);
    }
}
